package RemoteCommunication;

import java.net.InetSocketAddress;
import java.util.ArrayList;

import javax.net.ssl.SSLSocket;

import Client.Client;
import DDNS.DDNS;
import Queue.ACQueue;
import Queue.WriteQueue;
import Server.ConnectionHandler;
import Server.Server;

public class RealtimeClientCommunication implements Runnable{
	private Server server;
	private WriteQueue wq;
	private int houseID=1;
	public RealtimeClientCommunication(Server server, WriteQueue wq){
		this.server=server;
		this.wq=wq;
	}
	
	public void run(){
		realtimeAurdinoListener();
	}
	
	private void realtimeAurdinoListener(){
		while(true){
			//AurdniListener ar = new aurdinoListener();
			//ar.listenforUpdets();
			//realtimeCmdSender("securityAlaram_door_");
			//lyssnar på aurdino här
		}	
	}
	private void realtimeCmdSender(String cmd){
		for(int w=0;w<server.getThreads().size();w++){
			ConnectionHandler ch = server.getThreads().get(w);
			if(ch.getUser()!=null && ch.getUser().contains(String.valueOf(houseID))){
				ch.sendUpdate(cmd);
			}
		}
	}
	
	private ArrayList convertStringToArrayList(String stringList) {
		ArrayList taskList = new ArrayList();
		int lastSeparator = -1;
		for (int i = 0; i < stringList.length(); i++) {
			if (stringList.charAt(i) == '_') {
				taskList.add(stringList.subSequence(lastSeparator + 1, i));
				lastSeparator = i;
			}
		}
		return taskList;
	}
	
	private String convertArrayListToString(ArrayList arrayList) {
		String stringList = "";
		int lastSeparator = -1;
		for (int i = 0; i < arrayList.size(); i++) {
			stringList = stringList + arrayList.get(i) + "_";
		}
		return stringList;
	}
}
